#include <stdio.h>
#include <sys/time.h>
#include <time.h>

int main(int argc, const char **argv) {
    struct timespec t1; // ns
    struct timeval  t2; // us
    int ret = clock_gettime(CLOCK_MONOTONIC, &t1);
    if (ret != 0) {
        printf("clock gettime error<%d>\n", ret);
    } else {
        printf("clock gettime:%ld , %ld\n", t1.tv_sec, t1.tv_nsec / 1000);
    }

    ret = clock_gettime(CLOCK_REALTIME, &t1);
    if (ret != 0) {
        printf("clock gettime error<%d>\n", ret);
    } else {
        printf("clock gettime:%ld , %ld\n", t1.tv_sec, t1.tv_nsec / 1000);
    }

    ret = gettimeofday(&t2, NULL);
    if (ret != 0) {
        printf("clock gettime error<%d>\n", ret);
    } else {
        printf("clock gettime:%ld , %ld\n", t2.tv_sec, t2.tv_usec);
    }
    return 0;
}
